<template>
	<view class="staffCustomer">
		<nav-bars bgColor="#fff" fontColor="#000" :title="navBarTitle"></nav-bars>
		<!-- <view class="topBg">
			<view class="search">
				<view class="searchBox">
					<text class="iconfont">&#xe68e;</text>
					<input type="text" confirm-type="search" @confirm="searchFn" value="" v-model="searchInput" placeholder="搜索客户" />
				</view>
			</view>
		</view> -->
		<!-- :style="'margin-top:'+navHeight+'rpx;'" -->
		<view class="content">
			<view class="indexList">
				<view class="item" v-for="(item, index) in staffList" :key="index">
					<view class="checkBox">
						<view class="check" :class="{ checkActive: item.checked }" @click="selectCheck(item, index)"><text class="iconfont">&#xe69a;</text></view>
						<image :src="item.avatar?item.avatar:item.headimg" mode=""></image>
					</view>
					<view class="info">
						<view class="name">{{ item.name?item.name:item.nickname }}</view>
					</view>
				</view>
				<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" />
			</view>
		</view>
		<view class="btn">
			<view class="left">已选择{{ selectStaff.length }}个员工</view>
			<view class="right" @click="submitBack">确定</view>
		</view>
	</view>
</template>
<script>
import service_client from '@/service/client.js';
import { GetTeamList } from '@/service/superHK.js';
export default {
	name: '',
	components: {},
	data() {
		return {
			status: 'loadmore',
			iconType: 'flower',
			loadText: {
				loadmore: '轻轻上拉',
				loading: '努力加载中',
				nomore: '实在没有了~'
			},
			baseImg: this.$static,
			navBarTitle: '添加筛选人',
			searchInput: '',
			navHeight: 100,
			scrollTop: 0,
			staffList: [],
			selectStaff: [], //选中的筛选人
			page: 1,
			pagesize: 10,
			moduleType: '' //superHk-超级管家
		};
	},
	onLoad(options) {
		this.moduleType = options.moduleType
		let barHeight = uni.getStorageSync('StatusBarHeight').height * 2;
		this.navHeight = 308 - barHeight;
		this.getStaffList();
	},
	onReachBottom() {
		this.page++;
		if (this.moduleType == 'superHK') {
			let params = {
				page: this.page,
				pagesize: this.pagesize,
				status: 1
			};
			GetTeamList(params).then(res => {
				if (res.code == 1) {
					res.data.list.map(item => (item.checked = false));
					if (!res.data.list.length) {
						this.status = 'nomore';
					} else {
						this.status = 'loading';
					}
					this.staffList = this.staffList.concat(res.data.list);
				}
			});
		} else {
			let params = {
				is_qy: '',
				is_all: '1',
				page: this.page,
				pagesize: this.pagesize
			};
			service_client.getStaffList(params).then(res => {
				console.log(res, '筛选人列表');
				if (res.code == 1) {
					res.data.data.map(item => (item.checked = false));
					if (!res.data.data.length) {
						this.status = 'nomore';
					} else {
						this.status = 'loading';
					}
					this.staffList = this.staffList.concat(res.data.data);
				}
			});
		}
	},
	methods: {
		// 获取筛选人列表、
		getStaffList() {
			this.page = 1;

			if (this.moduleType == 'superHK') {
				let params = {
					page: this.page,
					pagesize: this.pagesize,
					status: 1
				};
				GetTeamList(params).then(res => {
					if (res.code == 1) {
						res.data.list.map(item => (item.checked = false));
						if (res.data.list.length < 10) {
							this.status = 'nomore';
						}
						this.staffList = res.data.list ? res.data.list : [];
					} else {
						this.status = 'nomore';
					}
				});
			} else {
				let params = {
					is_qy: '',
					is_all: '1',
					page: this.page,
					pagesize: this.pagesize
				};
				service_client.getStaffList(params).then(res => {
					console.log(res, '筛选人列表');
					if (res.code == 1) {
						res.data.data.map(item => (item.checked = false));
						if (res.data.data.length < 10) {
							this.status = 'nomore';
						}
						this.staffList = res.data.data ? res.data.data : [];
					} else {
						this.status = 'nomore';
					}
				});
			}
		},

		searchFn() {
			this.getStaffList();
		},

		// 选中
		selectCheck(item, index) {
			if (item.checked) {
				this.staffList[index].checked = false;
			} else {
				this.staffList[index].checked = true;
			}
			let arr = [];
			this.staffList.map(item => {
				if (item.checked) {
					arr.push(item);
				}
			});
			this.selectStaff = arr;
			console.log(this.selectStaff, '已选中的筛选人');
		},

		// 确定按钮
		submitBack() {
			console.log(this.tag_ids, '选择的标签');
			let pages = getCurrentPages(); //获取所有页面栈实例列表
			console.log(pages);
			let nowPage = pages[pages.length - 1]; //当前页页面实例
			let prevPage = pages[pages.length - 2]; //上一页页面实例
			console.log(prevPage);
			prevPage.$vm.staffList = this.selectStaff;
			uni.navigateBack({
				delta: 1
			});
		}
	}
};
</script>
<style lang="scss">
page {
	height: 100%;
}
.staffCustomer {
	height: 100%;
	background-color: #fff;
	position: relative;
	.topBg {
		width: 100%;
		height: 308rpx;
		background: url(https://manager.ryz1620.com/static/adminShop/client/bg.png) no-repeat;
		background-size: 100%;
		position: absolute;
		top: 0;
		left: 0;
		.search {
			margin-top: 197rpx;
			padding: 0 45rpx 0 32rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			image {
				width: 40rpx;
				height: 40rpx;
			}
			.searchBox {
				padding: 0 29rpx;
				display: flex;
				align-items: center;
				width: 690rpx;
				height: 80rpx;
				background-color: #f1f1f1;
				border-radius: 40rpx;
				.iconfont {
					color: #878787;
				}
				input {
					width: 100%;
					margin-left: 19rpx;
					font: 500 24rpx/80rpx PingFang SC;
					color: #878787;
				}
			}
		}
	}
	.content {
		padding: 0rpx 0 40rpx;
		margin-bottom: 110rpx;
		background-color: #fff;
		.selectBox {
			display: flex;
			padding-left: 32rpx;
			.item {
				display: flex;
				align-items: center;
				padding: 20rpx 30rpx;
				background-color: #fff;
				margin-right: 20rpx;
				border-radius: 8rpx;
				.iconfont {
					font-size: 20rpx;
					margin-left: 10rpx;
				}
			}
		}
		.indexList {
			padding: 40rpx 32rpx;
			.item {
				display: flex;
				align-items: center;
				.checkBox {
					display: flex;
					align-items: center;
					flex-shrink: 0;
					.check {
						width: 40rpx;
						height: 40rpx;
						border: 3rpx solid #d6d6d6;
						border-radius: 50%;
						margin-right: 20rpx;
						.iconfont {
							font-size: 30rpx;
							text-align: center;
							display: flex;
							line-height: 40rpx;
							justify-content: center;
							color: transparent;
						}
					}
					.checkActive {
						background-color: #c3ab7c;
						border-color: #c3ab7c;
						.iconfont {
							color: #fff;
						}
					}
					image {
						width: 95rpx;
						height: 95rpx;
						border-radius: 40%;
						flex-shrink: 0;
						margin-right: 32rpx;
					}
				}
				.info {
					width: 100%;
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 60rpx 0;
					border-bottom: 2rpx solid #f1f1f1;
					.name {
						font: bold 32rpx/32rpx PingFang SC;
						color: #333;
					}
				}
			}
			.u-load-more-wrap {
				padding: 20rpx 0;
			}
		}
	}
	.btn {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		height: 110rpx;
		z-index: 10;
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
		// height: calc(110rpx+ constant(safe-area-inset-bottom));			// height: calc(110rpx + env(safe-area-inset-bottom));			// padding-bottom: constant(safe-area-inset-bottom);			// padding-bottom: env(safe-area-inset-bottom);
		box-shadow: 0rpx -3rpx 12rpx 0rpx rgba(147, 147, 147, 0.09);
		.left {
			font: 500 26rpx/26rpx PingFang SC;
			color: #888888;
		}
		.right {
			width: 200rpx;
			height: 80rpx;
			border-radius: 40rpx;
			text-align: center;
			font: 500 28rpx/80rpx PingFang SC;
			color: #402200;
			background: linear-gradient(216deg, rgba(227, 210, 175, 0.94), rgba(195, 171, 124, 0.94));
		}
	}
}
</style>
